<template>
  <el-container id="home_box">
    <el-header>
      <div class="img_box">
        <!--logo 和 网站名称-->
        <img src="@/assets/1.png" alt="" style="width: 50px; height: 50px" />
        <span>硅谷后台管理系统</span>
      </div>
      <!--退出按钮-->
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <el-container>
      <el-aside width="260px">
        <!-- 侧边栏菜单 -->
        <el-menu :router="true" class="el-menu-vertical-demo" background-color="white" text-color="black"
          active-text-color="orange" :unique-opened="true">
          <el-submenu index="item.id" v-for="item in menuList" :key="item.id">
            <!-- 一级菜单的模板区域 -->
            <template slot="title">
              <!-- 一级菜单的图标 -->
              <i :class="item.icon"></i>
              <!-- 一级菜单的文字 -->
              <span style="font-size: 18px;">{{ item.name }}</span>
            </template>
            <!-- 没有子级的二级菜单 -->
            <el-menu-item :index="subItem.linkUrl" :key="subItem.id" v-for="subItem in item.children">
              <i :class="subItem.imageUrl"></i>
              <span slot="title">{{ subItem.name }}</span> </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      // 菜单列表
      menuList: [],
      // 图标数组
      // iconObj: {
      //   '125': 'iconfont icon-user',
      //   '103': 'iconfont icon-3702mima',
      //   '101': 'iconfont icon-shangpin',
      //   '102': 'iconfont icon-danju',
      //   '145': 'iconfont icon-baobiao',
      // }
    }
  },
  created() {
    this.getMenus()
  },
  methods: {
    // 获取所有的侧边栏菜单
    // async getMenuList() {
    //   const {data: res} = await this.$http.get('/menus')
    //   console.log("jap")
    //   console.log(res)
    //   this.menuList = res.data
    //   console.log(this.menuList);
    // },
    async getMenus() {
      const {data : res} = await this.$http.post('/systemMenus/tree')
      this.menuList = res
    },
    // 退出
    logout() {
      // 清空sessionStorage
      window.sessionStorage.clear();
      // 退回到登录页，路由跳转
      this.$router.push("/login");
    },
  },
};
</script>

<style scoped>
/* 父容器高度 */
#home_box {
  height: 100%;
}

.el-header {
  background-color: #b3c0d1;
  /* 
  在flex 布局的容器中，
  可以设置justify-content: space-between;实现两对齐
  */
  display: flex;
  justify-content: space-between;
  /* 当容器是flext，可以设置 align-items: center */
  align-items: center;

  div {
    display: flex;
    align-items: center;
  }

  span {
    margin-left: 20px;
  }
}

.el-aside {
  background-color: #d3dce6;
}

.el-menu {
  border-right: none;
}

.el-main {
  /* width: 100%; */
  padding: 0px;

  background-color: #e9eef3;
}
</style>